﻿namespace Sgr.EventBus
{
    /// <summary>
    /// 集成事件处理程序接口
    /// </summary>
    public interface IIntegrationEventHandler
    {
        /// <summary>
        /// 处理集成事件
        /// </summary>
        /// <param name="event"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        Task HandleAsync(IntegrationEvent @event, CancellationToken cancellationToken = default);
    }

    /// <summary>
    /// 集成事件处理程序接口
    /// </summary>
    /// <typeparam name="TIntegrationEvent"></typeparam>
    public interface IIntegrationEventHandler<in TIntegrationEvent> : IIntegrationEventHandler where TIntegrationEvent : IntegrationEvent
    {
        /// <summary>
        /// 处理集成事件
        /// </summary>
        /// <param name="event"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        Task HandleAsync(TIntegrationEvent @event, CancellationToken cancellationToken = default);

        /// <summary>
        /// 处理集成事件
        /// </summary>
        /// <param name="event"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        Task IIntegrationEventHandler.HandleAsync(IntegrationEvent @event, CancellationToken cancellationToken) => HandleAsync((TIntegrationEvent)@event, cancellationToken);
    }
}